package bizlogic;

import java.util.ArrayList;

import model.FacilityDTO;
import model.search.FacilitySearchDTO;
import dao.DAOException;
import dao.DAOFactory;
import dao.FacilityDAO;

public class FacilityManager {

	private FacilityDAO facilityDAO;

	public FacilityManager() {
		facilityDAO = DAOFactory.loadInstance().getFacilityDAO();
	}

	@SuppressWarnings("finally")
	public ArrayList<FacilityDTO> findFacilityByCriteria(FacilitySearchDTO fso) {
		ArrayList<FacilityDTO> currentList = new ArrayList<FacilityDTO>();
		try {
			currentList = facilityDAO.findFacilityByCriteria(fso);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentList;
		}

	}

	@SuppressWarnings("finally")
	public FacilityDTO getFacility(String name) {
		FacilityDTO currentFacility = null;
		try {
			currentFacility = facilityDAO.getFacility(name);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentFacility;
		}
	}
	
	public ArrayList<FacilityDTO> getFacilityByType(String type) {
		ArrayList<FacilityDTO> list = new ArrayList<FacilityDTO>();
		
		FacilitySearchDTO fs = new FacilitySearchDTO();
		fs.setType(type);
		fs.setStatus(1);
		
		try {
			System.out.println(fs);
			list = facilityDAO.findFacilityByCriteria(fs);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return list;
	}

	@SuppressWarnings("finally")
	public ArrayList<FacilityDTO> getAll() {
		ArrayList<FacilityDTO> currentFacilityList = new ArrayList<FacilityDTO>();
		try {
			currentFacilityList = facilityDAO.getAll();
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentFacilityList;
		}
	}

	public String insertFacility(FacilityDTO facility) {
		String error = "";
		try {
			facilityDAO.insertFacility(facility);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return error;
	}

	public String updateFacility(FacilityDTO facility) {
		String error = "";
		try {
			facilityDAO.updateFacility(facility);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return error;
	}

	public String deleteFacility(FacilityDTO facility) {
		String error = "";
		try {
			facilityDAO.deleteFacility(facility);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return error;
	}
}